<template>
	<view>
		<view class="wrap">
			<view class="u-tabs-box">
				<u-tabs-swiper activeColor="#ed3f14" ref="tabs" :list="list" :current="current" @change="change"
					:is-scroll="false" swiperWidth="750"></u-tabs-swiper>
			</view>
			<swiper class="swiper-box" :current="swiperCurrent" @transition="transition"
				@animationfinish="animationfinish">
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom">
						<view class="orderBox" v-for="item in goodsList">
							<view>订单ID：{{item.id}}</view>
							<view>订单编号：{{item.order_no}}</view>
							<view>下单时间：{{item.created_at}}</view>
							<view>总价：￥{{item.amount}}</view>
							<view>
								<u-button class="info-btn" @tap="toDetails(item.id,item.address_id)">查看详情</u-button>
							</view>
						</view>
					</scroll-view>

					<view v-if="showList.length == 0" class="u-flex-1 u-p-t-80">
						<u-empty text="暂无订单" mode="list"></u-empty>
					</view>
				</swiper-item>
				<swiper-item class="swiper-item">

					<view v-if="showList.length == 0" class="u-flex-1 u-p-t-80">
						<u-empty text="暂无订单" mode="list"></u-empty>
					</view>
				</swiper-item>
				<swiper-item class="swiper-item">

					<view v-if="showList.length == 0" class="u-flex-1 u-p-t-80">
						<u-empty text="暂无订单" mode="list"></u-empty>
					</view>
				</swiper-item>
				<swiper-item class="swiper-item">

					<view v-if="showList.length == 0" class="u-flex-1 u-p-t-80">
						<u-empty text="暂无订单" mode="list"></u-empty>
					</view>
				</swiper-item>
				<swiper-item class="swiper-item">

					<view v-if="showList.length == 0" class="u-flex-1 u-p-t-80">
						<u-empty text="暂无订单" mode="list"></u-empty>
					</view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [{
						name: '未支付'
					},
					{
						name: '已支付'
					},
					{
						name: '待收货'
					},
					{
						name: '已完成'
					},
					{
						name: '已过期',
					}
				],
				current: 0,
				swiperCurrent: 0,
				dx: 0,
				page: 1,
				status: 1,
				goodsList: [],
				showList: []
			};
		},
		onLoad() {
			this.getOrderList()
		},
		computed: {

		},
		methods: {
			// 页面数据
			async getOrderList() {
				const res = await this.$u.api.ordersList(this.status, this.page)
				this.showList = res.data
				this.goodsList = [...this.goodsList, ...res.data]
				// this.goodsList = res.data
				
				// for (var i = 0; i < this.goodsList.length; i++) {
				// 	const res = await this.$u.api.ordersListInfo(this.goodsList[i].id)
				// 	console.log(res)
				// }
			},
			// tab栏切换
			change(index) {
				this.swiperCurrent = index;
				this.status = index + 1
				this.page = 1
				this.getOrderList();
			},
			transition({
				detail: {
					dx
				}
			}) {
				this.$refs.tabs.setDx(dx);
			},
			animationfinish({
				detail: {
					current
				}
			}) {
				this.$refs.tabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
				this.status = current + 1
				this.getOrderList();
			},
			// 跳转订单详情
			toDetails(id,address){
				this.$u.route({
					url: '/pages/center/details',
					params: {
						id,
						address
					}
				})
			},
			reachBottom() {
				this.page = this.page + 1
				this.getOrderList()
			}
		}
	};
</script>

<style>
	/* #ifndef H5 */
	page {
		height: 100%;
		background-color: #f2f2f2;
	}

	/* #endif */
</style>

<style lang="scss" scoped>
	.order {
		width: 710rpx;
		background-color: #ffffff;
		margin: 20rpx auto;
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 20rpx;
		font-size: 28rpx;

		.top {
			display: flex;
			justify-content: space-between;

			.left {
				display: flex;
				align-items: center;

				.store {
					margin: 0 10rpx;
					font-size: 32rpx;
					font-weight: bold;
				}
			}

			.right {
				color: $u-type-warning-dark;
			}
		}

		.item {
			display: flex;
			margin: 20rpx 0 0;

			.left {
				margin-right: 20rpx;

				image {
					width: 200rpx;
					height: 200rpx;
					border-radius: 10rpx;
				}
			}

			.content {
				.title {
					font-size: 28rpx;
					line-height: 50rpx;
				}

				.type {
					margin: 10rpx 0;
					font-size: 24rpx;
					color: $u-tips-color;
				}

				.delivery-time {
					color: #e5d001;
					font-size: 24rpx;
				}
			}

			.right {
				margin-left: 10rpx;
				padding-top: 20rpx;
				text-align: right;

				.decimal {
					font-size: 24rpx;
					margin-top: 4rpx;
				}

				.number {
					color: $u-tips-color;
					font-size: 24rpx;
				}
			}
		}

		.total {
			margin-top: 20rpx;
			text-align: right;
			font-size: 24rpx;

			.total-price {
				font-size: 32rpx;
			}
		}

		.bottom {
			display: flex;
			margin-top: 40rpx;
			padding: 0 10rpx;
			justify-content: space-between;
			align-items: center;

			.btn {
				line-height: 52rpx;
				width: 160rpx;
				border-radius: 26rpx;
				border: 2rpx solid $u-border-color;
				font-size: 26rpx;
				text-align: center;
				color: $u-type-info-dark;
			}

			.evaluate {
				color: $u-type-warning-dark;
				border-color: $u-type-warning-dark;
			}
		}
	}

	.centre {
		text-align: center;
		margin: 200rpx auto;
		font-size: 32rpx;

		image {
			width: 164rpx;
			height: 164rpx;
			border-radius: 50%;
			margin-bottom: 20rpx;
		}

		.tips {
			font-size: 24rpx;
			color: #999999;
			margin-top: 20rpx;
		}

		.btn {
			margin: 80rpx auto;
			width: 200rpx;
			border-radius: 32rpx;
			line-height: 64rpx;
			color: #ffffff;
			font-size: 26rpx;
			background: linear-gradient(270deg, rgba(249, 116, 90, 1) 0%, rgba(255, 158, 1, 1) 100%);
		}
	}

	.wrap {
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top));
		width: 100%;
	}

	.swiper-box {
		flex: 1;
	}

	.swiper-item {
		height: 100%;
	}


	.orderBox {
		background-color: white;
		padding: 30rpx;
		margin: 30rpx;
		border-radius: 20rpx;
		
		.info-btn{
			margin: 30rpx;
		}
	}
</style>
